import { AxiosPromise } from 'axios'
import request from './request'
//获取提现设置
export function getWithdrawSet() {
  return request({
    url: '/set/getWithdrawSet',
    method: 'get',
  })
}
// 保存提现设置
export function saveWithdrawSet(data) {
  return request({
    url: '/set/saveWithdrawSet',
    method: 'put',
    data,
  })
}
// 获取可提现工单列表
export function getWithdrawOrderList(data, networkId, networkEmpId) {
  return request({
    url: `/withdraw/getWithdrawOrderList/${networkId}/${networkEmpId}`,
    method: 'post',
    data,
  })
}
// 保存提现单
export function saveWithdraw(data) {
  return request({
    url: `/withdraw/save`,
    method: 'post',
    data,
  })
}

// 获取提现单列表
export function getWithdrawList(data) {
  return request({
    url: '/withdraw/getList',
    method: 'post',
    data,
  })
}

// 根据商家获取服务人员下拉数据
export function getNetworkEmpSelect(data) {
  return request({
    url: '/networkSelect/getNetworkEmpSelect',
    method: 'post',
    data,
  })
}
// 根据服务人员ID获取对应部门下拉数据
export function getNetworkByNetworkEmpIdSelect(networkEmpId) {
  return request({
    url: '/networkSelect/getNetworkByNetworkEmpIdSelect/' + networkEmpId,
    method: 'get',
  })
}
// 获取服务人员银行卡
export function getNetworkBandSelect(networkEmpId) {
  return request({
    url: '/networkSelect/getNetworkBandSelect/' + networkEmpId,
    method: 'post',
  })
}
// 根据部门ID获取提现手续费策略
export function getWithdrawHandlingFeeStrategy(networkId) {
  return request({
    url: '/network/strategy/getWithdrawHandlingFeeStrategy/' + networkId,
    method: 'get',
  })
}
// 获取提现单详情
export function getWithdrawDetail(id) {
  return request({
    url: `/withdraw/getDetail/${id}`,
    method: 'get',
  })
}
//根据提现单ID获取提现工单
export function getWithdrawOrder(id) {
  return request({
    url: `/withdraw/getWithdrawOrder/${id}`,
    method: 'get',
  })
}
//根据提现单ID获取操作日志
export function getWithdrawLog(data, id) {
  return request({
    url: `/withdraw/getWithdrawLog/${id}`,
    method: 'post',
    data,
  })
}
//审核提现单
export function checkWithdraw(data) {
  return request({
    url: `/withdraw/checkWithdraw`,
    method: 'post',
    data,
  })
}
// 获取更改提现单前的查询
export function getBeforeUpdateSelect(id) {
  return request({
    url: `/withdraw/getBeforeUpdateSelect/${id}`,
    method: 'get',
  })
}
// 批量完成打款
export function finishWithdraw(data) {
  return request({
    url: `/withdraw/finishWithdraw`,
    method: 'post',
    data,
  })
}

/**
 * 导出结算列表
 * @param {FinanceAPIRequest.ExportSettlementList} data - 请求参数
 */
export const exportSettlementList = (data: FinanceAPIRequest.ExportSettlementList) => {
  return request({
    url: '/withdraw/exportWithdrawToExcel',
    method: 'post',
    data,
    responseType: 'blob',
  })
}

/**
 * 获取收款单列表
 * @param {WithdrawalAPIRequest.GetReceivePaymentListParam} data - 请求参数
 * @param {string} data.endTime - 收款单生成结束时间
 * @param {number} data.limit - 每页显示数量
 * @param {number} data.page - 当面页码
 * @param {string} data.receivePaymenNo - 收款单号
 * @param {string} data。startTime - 收款单生成开始时间
 * @param {(1|2)} data.status - 收款单状态：1-待审核，2-已审核
 * @param {string} data.workNo - 工单单号
 */
export const getReceivePaymentList = (
  data: WithdrawalAPIRequest.GetReceivePaymentListParam,
): AxiosPromise<WithdrawalAPIResponse.ReceivePaymentList> => {
  return request({
    url: '/finance/userReceivePayment/getReceivePaymentList',
    method: 'post',
    data,
  })
}

/**
 * 根据客户ID获取未向客户收款的工单列表
 * @param {string} userId - 客户id
 * @param {object} data - 请求参数
 * @param {number} data.limit - 一页显示多少条
 * @param {number} data.page - 当前页码
 */
export const getUserUnpaidList = (
  userId: string,
  data: { limit: number; page: number },
): AxiosPromise<WithdrawalAPIResponse.UserUnpaidList> => {
  return request({
    url: `/finance/userReceivePayment/getUserWaitReceivePaymentOrderList/${userId}`,
    method: 'post',
    data,
  })
}

/**
 * 保存收款单
 * @param {WithdrawalAPIRequest.ReceivePaymentForm} data 请求参数
 */
export const receivePaymentFormSave = (
  data: WithdrawalAPIRequest.ReceivePaymentForm,
): AxiosPromise<APIResponse> => {
  return request({
    url: '/finance/userReceivePayment/saveReceivePaymen',
    method: 'post',
    data,
  })
}

/**
 * 收款单导出未excel
 * @param {WithdrawalAPIRequest.GetReceivePaymentListParam} data - 请求参数
 * @param {string} data.endTime - 收款单生成结束时间
 * @param {number} data.limit - 每页显示数量
 * @param {number} data.page - 当面页码
 * @param {string} data.receivePaymenNo - 收款单号
 * @param {string} data。startTime - 收款单生成开始时间
 * @param {(1|2)} data.status - 收款单状态：1-待审核，2-已审核
 * @param {string} data.workNo - 工单单号
 */
export const receivePaymentExportExcel = (
  data: WithdrawalAPIRequest.GetReceivePaymentListParam,
) => {
  return request({
    url: '/finance/userReceivePayment/exportReceivePaymentToExcel',
    method: 'post',
    data,
    responseType: 'blob',
  })
}

/**
 * 获取收款单列表状态数量
 */
export const getReceivePaymentListQty =
  (): AxiosPromise<WithdrawalAPIResponse.ReceivePaymentListQty> => {
    return request({
      url: '/finance/userReceivePayment/getReceivePaymentStatusQty',
      method: 'get',
    })
  }

/**
 * 保存审核收款单
 * @param {WithdrawalAPIRequest.ReceivePaymentCheck} data - 请求参数
 * @param {(1)} data.checkResultType - 审核结果：1-审核通过
 * @param {Array<string>} data.receivePaymentIds - 收款单ID
 * @param {string} data.remark - 审核备注
 */
export const checkReceivePayment = (
  data: WithdrawalAPIRequest.ReceivePaymentCheck,
): AxiosPromise<APIResponse> => {
  return request({
    url: '/finance/userReceivePayment/saveCheckReceivePayment',
    method: 'post',
    data,
  })
}

/**
 * 根据收款单ID获取收款单详情
 * @param {string} id - 收款单id
 */
export const getReceivePaymentDetail = (
  id: string,
): AxiosPromise<WithdrawalAPIResponse.ReceivePaymentDetail> => {
  return request({
    url: `/finance/userReceivePayment/getReceivePaymentDetail/${id}`,
    method: 'get',
  })
}

/**
 * 根据收款单ID获取详情单工单明细
 * @param {string} id 收款单ID
 */
export const getReceivePaymentDetailOrderList = (
  id: string,
): AxiosPromise<WithdrawalAPIResponse.ReceivePaymentDetailOrderList> => {
  return request({
    url: `/finance/userReceivePayment/getReceivePaymentOrderDetail/${id}`,
    method: 'get',
  })
}

/**
 * 反写未同步的云星空的收款单
 * @param {string} id - 收款单id
 */
export const writeBackNoSyncReceivePayment = (id: string): AxiosPromise<APIResponse> => {
  return request({
    url: `/finance/userReceivePayment/yxkSyncData/${id}`,
    method: 'post',
  })
}
